var invertTree = function (root) {
    if (root === null) {
        return null; // 空树直接返回null
    }
    // 递归翻转左右子树
    let left = invertTree(root.left);
    let right = invertTree(root.right);
    // 交换左右子树
    root.left = right;
    root.right = left;
    return root;
};